﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
using System.Threading.Tasks;
using Fast.Framework.Models;

namespace Fast.Framework.Interfaces
{

    /// <summary>
    /// 数据库上下文接口类
    /// </summary>
    /// <typeparam name="TDbOptions"></typeparam>
    public interface IDbContext<TDbOptions> where TDbOptions : DbOptions
    {

        /// <summary>
        /// Ado
        /// </summary>
        IAdo<TDbOptions> Ado { get; }

        /// <summary>
        /// 插入
        /// </summary>
        /// <param name="entity">实体</param>
        /// <returns></returns>
        IInsert<T, TDbOptions> Insert<T>(T entity) where T : class;

        /// <summary>
        /// 插入
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="entityList">实体列表</param>
        /// <returns></returns>
        IInsert<T, TDbOptions> Insert<T>(List<T> entityList) where T : class;

        /// <summary>
        /// 插入
        /// </summary>
        /// <param name="keyValues">键值</param>
        /// <returns></returns>
        IInsert<T, TDbOptions> Insert<T>(Dictionary<string, object> keyValues) where T : class;

        /// <summary>
        /// 删除
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <returns></returns>
        IDelete<T, TDbOptions> Delete<T>() where T : class;

        /// <summary>
        /// 删除
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="obj">对象(这是一个虚拟对象主要是为了匿名类型可以使用Where方法)</param>
        /// <returns></returns>
        IDelete<T, TDbOptions> Delete<T>(T obj) where T : class;

        /// <summary>
        /// 更新
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="entity">实体</param>
        /// <returns></returns>
        IUpdate<T, TDbOptions> Update<T>(T entity) where T : class;

        /// <summary>
        /// 更新
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="entityList">实体列表</param>
        /// <param name="whereColumns">条件列</param>
        /// <returns></returns>
        IUpdate<T, TDbOptions> Update<T>(List<T> entityList) where T : class;

        /// <summary>
        /// 更新
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="keyValues">键值</param>
        /// <returns></returns>
        IUpdate<T, TDbOptions> Update<T>(Dictionary<string, object> keyValues) where T : class;

        /// <summary>
        /// 更新
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="expression">表达式</param>
        /// <returns></returns>
        IUpdate<T, TDbOptions> Update<T>(Expression<Func<T, T>> expression) where T : class;

        /// <summary>
        /// 大数据
        /// </summary>
        /// <returns></returns>
        IBigData<TDbOptions> BigData();

        /// <summary>
        /// 查询
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <returns></returns>
        IQuery<T, TDbOptions> Query<T>() where T : class, new();

        /// <summary>
        /// 联合
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="querys">查询</param>
        /// <returns></returns>
        IQuery<T, TDbOptions> Union<T>(params IQuery<T, TDbOptions>[] querys) where T : class;

        /// <summary>
        /// 联合
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="querys">查询</param>
        /// <returns></returns>
        IQuery<T, TDbOptions> Union<T>(List<IQuery<T, TDbOptions>> querys) where T : class;

        /// <summary>
        /// 联合所有
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="querys">查询</param>
        /// <returns></returns>
        IQuery<T, TDbOptions> UnionAll<T>(params IQuery<T, TDbOptions>[] querys) where T : class;

        /// <summary>
        /// 联合所有
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="querys">查询</param>
        /// <returns></returns>
        IQuery<T, TDbOptions> UnionAll<T>(List<IQuery<T, TDbOptions>> querys) where T : class;
    }
}
